<template>
  <el-dialog :title="isAdd?'添加用户':'编辑用户'" :close-on-click-modal="false"
             :visible.sync="isShow" width="25%" @close="handleClose"
             :show-close="false">

    <el-form ref="form" :model="user" label-position="left">
      <el-form-item label="账号类型：" v-if="isAdd">
        <el-radio-group v-model="user.type">
          <el-radio-button label="0">管理员</el-radio-button>
          <el-radio-button label="1">医护人员</el-radio-button>
          <el-radio-button label="2">学生</el-radio-button>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="用户名" v-if="isAdd">
        <el-input v-model="user.userName" placeholder="请输入用户名"></el-input>
      </el-form-item>
      <el-form-item label="姓名" v-if="!isAdd">
        <el-input v-model="user.name" placeholder="请输入姓名"></el-input>
      </el-form-item>
      <el-form-item label="密码" v-if="isAdd">
        <el-input v-model="user.password" placeholder="请输入密码" type="password"></el-input>
      </el-form-item>
      <el-form-item label="手机" v-if="!isAdd">
        <el-input v-model="user.phoneNum" placeholder="请输入手机"></el-input>
      </el-form-item>
      <el-form-item label="邮箱">
        <el-input v-model="user.email" placeholder="请输入邮箱"></el-input>
      </el-form-item>
    </el-form>

    <span slot="footer" class="dialog-footer">
      <el-button @click="closeDialog">取 消</el-button>
      <el-button type="primary" @click="handleSubmit">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  props: {
    isShow: {
      type: Boolean,
      default: false
    },
    user: {
      type: Object,
      default: {}
    },
    isAdd: {
      type: Boolean,
      default: true
    }
  },
  methods: {
    handleClose() {
      this.$emit('handleClose')
    },
    closeDialog() {
      this.$emit('closeDialog')
    },
    handleSubmit() {
      this.$emit('handleSubmit', this.user)
    }
  }
}
</script>

<style scoped>

</style>
